package com.easy.component.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * 描述: {描述}
 * 作者:
 * 创建日期: 2017/11/2 10:13
 * 修改日期: 2017/11/2
 * 版本: {版本}
 */
public class DeviceUtils {
    private static final String TAG = "ManifestUtils";

    public DeviceUtils() {
    }

    public static String getMetaData(Context context, String key) {
        ApplicationInfo app_info = null;

        try {
            app_info = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128);
            if (app_info != null && app_info.metaData != null) {
                Object obj = app_info.metaData.get(key);
                return obj != null ? obj.toString() : "";
            } else {
                return "";
            }
        } catch (PackageManager.NameNotFoundException var4) {
            LogUtils.e("ManifestUtils", "getMetaData error", var4);
            return "";
        }
    }

    public static String getVersionName(Context context) {
        String version = "0.0";

        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            version = packInfo.versionName;
        } catch (Exception var4) {
            LogUtils.e("ManifestUtils", "getVersionName error", var4);
        }

        return version;
    }
}
